home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3.iso
/
chapte22
/
ex8.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-04
|
4KB
|
79 lines
#include <genstub.c>
#include <winnls.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static BOOL fEnglish = TRUE;
switch (uMsg)
{
case WM_COMMAND:
switch ( LOWORD( wParam ) )
{
case IDM_TEST:
{
int iChars;
TCHAR szNoun[16]; // noun comes 1st in Spanish
TCHAR szAdjective[16]; // adj comes 1st in English
TCHAR szMessageFormat[10]; // smart format string
LPTSTR pArgs[16]; // list of args
PVOID pBuffer = 0; // system allocates buffer
HDC hDC = GetDC( hWnd );
static int row = 0;
pArgs[0] = szAdjective; // argument 1 = adjective
pArgs[1] = szNoun; // argument 2 = noun
pArgs[2] = 0;
fEnglish = !fEnglish;
if (fEnglish) { // If English.
lstrcpy( szMessageFormat, "%1 %2" );
lstrcpy( szNoun, "States" );
lstrcpy( szAdjective, "United" );
}
else { // If Spanish.
lstrcpy(szMessageFormat, "%2 %1" );
lstrcpy( szNoun, "Estados" );
lstrcpy( szAdjective, "Unidos" );
}
// Do smart formatting
iChars = FormatMessage( FORMAT_MESSAGE_FROM_STRING |
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_ARGUMENT_ARRAY ,
szMessageFormat, 0, 0, &pBuffer,
63, pArgs );
// Do output to screen.
if (GetLastError()==ERROR_SUCCESS) {
TCHAR szOutputBuffer[128]; // output buffer
lstrcpy( szOutputBuffer,
"Comparison of Format Message and wvsprintf" );
TextOut( hDC, 0, row, szOutputBuffer,
lstrlen( szOutputBuffer ) );
TextOut( hDC, 0, row + 20, szOutputBuffer, wsprintf(
szOutputBuffer, "Formatted message: %s",
pBuffer ) );
TextOut( hDC, 0, row + 40, szOutputBuffer, wvsprintf(
szOutputBuffer, "Order of the args: %s %s",
pArgs ) );
row += 60;
// Free the memory system allocated.
if (pBuffer)
LocalFree( pBuffer );
}
ReleaseDC( hWnd, hDC );
}
break;
case IDM_EXIT:
DestroyWindow( hWnd );
break;
}
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
}
return( NULL );
}